{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ee693834-becf-4bef-be66-5980309d13dc",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from osgeo import gdal\n",
    "from osgeo import ogr\n",
    "from osgeo import osr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "71256b29-a883-48f5-9faf-902b086520f1",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2700\n",
      "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]\n"
     ]
    }
   ],
   "source": [
    "raster_path =  \"/storage/data/raster/world.tif\"\n",
    "dataset = gdal.Open(raster_path)\n",
    "print(dataset.RasterXSize)\n",
    "\n",
    "input_srs = osr.SpatialReference()\n",
    "input_srs.SetFromUserInput('EPSG:4326')\n",
    "input_srs_wkt = input_srs.ExportToWkt()\n",
    "print(input_srs_wkt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f1f8c066-e5f9-43e4-a72a-4ee7786ca471",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alphaband = dataset.GetRasterBand(1).GetMaskBand()\n",
    "alphaband.GetMaskFlags() & gdal.GMF_ALPHA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "4f526ba6-9490-4c91-87e8-cd8c8c885d09",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "32\n",
      "31\n",
      "30\n",
      "29\n",
      "28\n",
      "27\n",
      "26\n",
      "25\n",
      "24\n",
      "23\n",
      "22\n",
      "21\n",
      "20\n",
      "19\n",
      "18\n",
      "17\n",
      "16\n",
      "15\n",
      "14\n",
      "13\n",
      "12\n",
      "11\n",
      "10\n",
      "9\n",
      "8\n",
      "7\n",
      "6\n",
      "5\n",
      "4\n",
      "3\n",
      "2\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "for i in range(32,0,-1):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "27dd1e3e-22dc-4cbb-80b7-7af4e8844ab8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "32\n"
     ]
    }
   ],
   "source": [
    "print(2**5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "2fbb0c60-5732-44bc-9450-63f993e8fd97",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(1, 2)]\n"
     ]
    }
   ],
   "source": [
    "arr=[]\n",
    "arr.append((1,2))\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "68791267-ddf6-4872-b2af-b53a323e69e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0,\n",
       " 1,\n",
       " 2,\n",
       " 3,\n",
       " 4,\n",
       " 5,\n",
       " 6,\n",
       " 7,\n",
       " 8,\n",
       " 9,\n",
       " 10,\n",
       " 11,\n",
       " 12,\n",
       " 13,\n",
       " 14,\n",
       " 15,\n",
       " 16,\n",
       " 17,\n",
       " 18,\n",
       " 19,\n",
       " 20,\n",
       " 21,\n",
       " 22,\n",
       " 23,\n",
       " 24,\n",
       " 25,\n",
       " 26,\n",
       " 27,\n",
       " 28,\n",
       " 29,\n",
       " 30,\n",
       " 31]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0, 32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "c061049f-f092-4f92-b4a3-0e618f5e8a63",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 32)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0, 32)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "4843d45f-33d0-4942-84be-4e145379af31",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "range(0, 32)\n"
     ]
    }
   ],
   "source": [
    "arr = range(0,32)\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "edc11660-ca61-42ed-9088-10fe61843a54",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str = \"/a/b/c\"\n",
    "str.startswith(\"/b\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09cedadf-7adc-495c-b80d-74fa65501965",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "284386fa-45fb-455a-947f-cb0c31dd526a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 or 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "f2b27b64-1788-41b3-9d11-08f0d0e6beec",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0 or 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "91720192-aac1-47a7-bca0-079981098b6c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 or 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "5d09be49-a2c5-4a1d-9ef3-fd11f35f04d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<_thread._local object at 0x7f99233caea0>\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "import threading\n",
    "threadLocal = threading.local()\n",
    "print(threadLocal)\n",
    "cached_ds = getattr(threadLocal, \"cached_ds\", None)\n",
    "print(cached_ds)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "b226ecd6-c902-438c-8435-6cd5a67cb939",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 1)\n"
     ]
    }
   ],
   "source": [
    "overview_tile=(1,1)\n",
    "print(overview_tile)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "d6f4961c-bcf8-4a20-8c9f-9478b3f983b7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{(1, 1): [(22, 23), (23, 24), (24, 25)], (2, 2): [(22, 23), (23, 24), (24, 25)]}\n",
      "dict_values([[(22, 23), (23, 24), (24, 25)], [(22, 23), (23, 24), (24, 25)]])\n",
      "[[(22, 23), (23, 24), (24, 25)], [(22, 23), (23, 24), (24, 25)]]\n"
     ]
    }
   ],
   "source": [
    "overview_to_bases = {}\n",
    "overview_to_bases[(1,1)] = []\n",
    "overview_to_bases[(1,1)].append((22,23))\n",
    "overview_to_bases[(1,1)].append((23,24))\n",
    "overview_to_bases[(1,1)].append((24,25))\n",
    "overview_to_bases[(2,2)] = []\n",
    "overview_to_bases[(2,2)].append((22,23))\n",
    "overview_to_bases[(2,2)].append((23,24))\n",
    "overview_to_bases[(2,2)].append((24,25))\n",
    "print(overview_to_bases)\n",
    "print(overview_to_bases.values())\n",
    "print(list(overview_to_bases.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4deace75-9a10-4f85-8634-60d789eb0f5b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Options: {'verbose': True, 'title': 'world.tif', 'profile': 'mercator...}\n",
      "Input: /storage/data/raster/world.tif\n",
      "Output: /storage/temp/tiles/world\n",
      "Cache: 787.2240228652954 MB\n",
      "\n",
      "Begin tiles details calc\n"
     ]
    }
   ],
   "source": [
    "import gdal2tiles\n",
    "gdal2tiles.generate_tiles('/storage/data/raster/world.tif','/storage/temp/tiles/world', nb_processes=2, verbose=True, zoom='1-5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0bf5a288-4bf5-45c1-893b-4fc9b368e292",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pygdal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eaaaf1ae-761c-4207-a0bc-d4c88814c435",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py39",
   "language": "python",
   "name": "py39"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
